package mvc.handlers;

import facade.StudenteFacadeRemote;

import mvc.framework.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 * Handler per gestire l'azione di visualizzazione del profilo di un utente
 * 
 * @author Grillo
 */
public class ListaStudentiHandler extends AbsRequestHandler {

    private final static String ACTION_NAME = "listaStudenti";

    public ListaStudentiHandler(DialogHandler dHandler) {
        super(dHandler);
    }

    public String getActionName() {
        return ACTION_NAME;
    }

    public void setNextPage() {
        nextPage = "/views/listaStudenti.jsp";
    }
    
    public int validate() {
        return SUCCESS;
    }

    public int execute() {
        StudenteFacadeRemote studenteFacade = null;

        //Bind agli EJB
        try {
            Context c = new InitialContext();
            studenteFacade = (StudenteFacadeRemote) c.lookup("facade.StudenteFacadeRemote");
        } catch (NamingException ne) {}

        SessionManager.setAttribute(dialogHandler.getSession(), "listaStudenti", studenteFacade.findAll());

        return SUCCESS;
    }

    @Override
    public IRequestHandler clone(DialogHandler dHandler) throws CloneNotSupportedException {
        return new ListaStudentiHandler(dHandler);
    }
}